#include "mainwindow.h"

#include <QApplication>
#include <QCoreApplication>
#include <QFontDatabase>
#include <QDebug>
#include <QMessageBox>

#include "svgimage.h"
#include "platetableabstractmodel.h"
#include "tools.h"

int main(int argc, char *argv[])
{

// 高分辨率适配
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

// opengl适配
#if QT_CONFIG(opengl)
    qDebug() << "支持opengl";
#else
    qDebug() << "不支持";
#endif
    QApplication a(argc, argv);

    // 加载字体簇(字体簇要与.exe文件在同一个路径下)
    QString processingPath =  QCoreApplication::applicationDirPath();
    int fontId = QFontDatabase::addApplicationFont(processingPath + "/fonts/Alibaba-PuHuiTi-Regular.ttf");
    QFontDatabase::addApplicationFont(processingPath + "/fonts/Alibaba-PuHuiTi-Bold.ttf");
    QFontDatabase::addApplicationFont(processingPath + "/fonts/Alibaba-PuHuiTi-Heavy.ttf");
    QFontDatabase::addApplicationFont(processingPath + "/fonts/Alibaba-PuHuiTi-Light.ttf");
    QFontDatabase::addApplicationFont(processingPath + "/fonts/Alibaba-PuHuiTi-Medium.ttf");

    // 设置默认字体
    if (fontId != -1) {
        QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
        if (!fontFamilies.isEmpty()) {
            QString familyName = fontFamilies.first();
            QFont font(familyName);
            a.setFont(font);
        }
    }

    // 注册组件
    SvgImage::declareQML();
    PlateTableAbstractModel::declareQML();
    declareGLOBALQML();

    MainWindow w;
    w.show();

    QFontDatabase database;
    if(!database.hasFamily("Alibaba PuHuiTi")){
        QMessageBox::warning(nullptr, "字体簇", "字体加载失败");
    }

    return a.exec();
}
